﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SuperStarProject.Models;
using SuperStarProject.DAO;

namespace SuperStarProject.Controllers
{
    public class PhieuChonQuaTangController : Controller
    {
        //
        // GET: /PhieuChonQuaTang/

        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public ActionResult CreateDSQuaTang(string maPhieuMuaHang)
        {
            DSQuaTang item = new DSQuaTang();
            item.MaPhieuMuaHang = maPhieuMuaHang;
            var temp = PhieuMuaHangDAO.GetDetails(maPhieuMuaHang);
            item.MaSP = temp.MaSP;
            item.TongDiemThuong = temp.TongDiemThuong;
            item.TongDiemThuongDaSuDung = temp.TongDiemThuongDaSuDung;
            item.SoLuong0 = 0;
            item.SoLuong1 = 0;
            item.SoLuong2 = 0;
            item.SoLuong3 = 0;
            item.SoLuong4 = 0;
            item.SoLuong5 = 0;
            item.SoLuong6 = 0;
            item.SoLuong7 = 0;
            item.SoLuong8 = 0;
            item.SoLuong9 = 0;
            return View(item);
        }
        [HttpPost]
        public ActionResult CreateDSQuaTang(DSQuaTang model)
        {
            PhieuChonQuaTangDAO.Create(model);
            return RedirectToAction("ViewDetails", "PhieuMuaHang", new { model.MaPhieuMuaHang});
        }
        [HttpGet]
        public ActionResult EditDSQuaTang(string maPhieuMuaHang)
        {
            DSQuaTang item = new DSQuaTang();
            item.MaPhieuMuaHang = maPhieuMuaHang;
            var temp = PhieuMuaHangDAO.GetDetails(maPhieuMuaHang);
            item.MaSP = temp.MaSP;
            item.TongDiemThuong = temp.TongDiemThuong;
            item.TongDiemThuongDaSuDung = temp.TongDiemThuongDaSuDung;
            // Cho nay can lay danhsach qua, so luong tung mon qua dc chon de set vao danh sach cho dung.
            List<int> lstSoLuong = new List<int>();
            item.SoLuong0 = 0;
            item.SoLuong1 = 0;
            item.SoLuong2 = 0;
            item.SoLuong3 = 0;
            item.SoLuong4 = 0;
            item.SoLuong5 = 0;
            item.SoLuong6 = 0;
            item.SoLuong7 = 0;
            item.SoLuong8 = 0;
            item.SoLuong9 = 0;
            return View(item);
        }
        [HttpPost]
        public ActionResult EditDSQuaTang(DSQuaTang model)
        {
            PhieuChonQuaTangDAO.Update(model);
            return RedirectToAction("ViewDetails", "PhieuMuaHang", new { model.MaPhieuMuaHang });
        }

        public ActionResult ShowDSQuaTangTheoMaPhieuMuaHangUC(string maphieumuahang)
        {
            var lstitem = PhieuChonQuaTangDAO.ShowAllQuaTangTheoPhieuMuaHang(maphieumuahang);
            return View(lstitem);
        }

    }
}
